package jsu.lipengcheng.trafficnet.task;

import jsu.lipengcheng.trafficnet.mapper.ActivityMapper;
import jsu.lipengcheng.trafficnet.pojo.Activity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.List;

@Component
@Slf4j
public class StatusTask {
    @Autowired
    private ActivityMapper activityMapper;

    /**
     * 检查活动过期
     */
    //@Scheduled(cron = "0 * * * * ? ")//每分钟触发一次
    @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点触发一次
    public void statusTask() {
        List<Activity> activityList=activityMapper.selectList(null);
        for(Activity activity:activityList){
            LocalDate endTime = activity.getEndTime();
            LocalDate currentDate = LocalDate.now();
            if (endTime.isBefore(currentDate)){
                activity.setStatus(0);
                activityMapper.updateById(activity);
            }
        }
    }
}
